﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcWeb.Controllers
{
    public class ConfigOtherTypeController :BaseController
    {
        //
        // GET: /ConfigOtherType/

        public ActionResult Index()
        {
            List<EAM.Model.AssetConfigOtherType> assetConfigOtherTypeList = db.AssetConfigOtherType.ToList();
            return View(assetConfigOtherTypeList);
        }

        public ActionResult Edit(int id)
        {
            EAM.Model.AssetConfigOtherType model = db.AssetConfigOtherType.Find(id);
            return View(model);
        }

        [HttpPost]
        public ActionResult Edit(int id, EAM.Model.AssetConfigOtherType viewModel )
        {
            var user = System.Web.Security.Membership.GetUser();
            var guid = (Guid)user.ProviderUserKey;

            if (id == -1)
            {
                //添加关联信息
                EAM.Model.AssetConfigOtherType model = new EAM.Model.AssetConfigOtherType()
                {
                    ConfigOtherTypeName = viewModel.ConfigOtherTypeName,
                    ConfigOtherTypeDesc = viewModel.ConfigOtherTypeDesc,
                    LastUpdateMember = guid,
                    LastUpdateTime = DateTime.Now
                };
                db.AssetConfigOtherType.Add(model);
            }
            else
            {
                var model = db.AssetConfigOtherType.Find(id);
                db.AssetConfigOtherType.Attach(model);

                model.ConfigOtherTypeName = viewModel.ConfigOtherTypeName;
                model.ConfigOtherTypeDesc = viewModel.ConfigOtherTypeDesc;
                model.LastUpdateMember = guid;
                model.LastUpdateTime = DateTime.Now;
            }
            db.SaveChanges();

            return RedirectToAction("index");
        }

    }
}
